/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.dat076.datesite.controllers;

import edu.chl.dat076.datesite.ejbs.UserEJBLocal;
import edu.chl.dat076.datesite.entities.SiteUser;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author Mikey
 */
@ManagedBean
@ViewScoped
public class FavoritesBackingBean implements Serializable {

    @EJB
    private UserEJBLocal userJPACtrl;
    
    private List<SiteUser> friends;

    private SiteUser selectedUser;
    
    private SiteUser user;
	
	private String msgUser;

    /**
     * TODO: feed users to this bean instead of getting
     * them from the db
     */
   
    @PostConstruct
    public void postConstruct (){
        setUser(userJPACtrl.getUser(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user").toString()));
        friends = user.getFriends();
    }

    public List<SiteUser> getFriends() {
        return friends;
    }

    public void setFriends(List<SiteUser> friends) {
        this.friends = friends;
    }

    public SiteUser getUser() {
        return user;
    }

    public void setUser(SiteUser user) {
        this.user = user;
    }
    
    public void setSelectedUser(SiteUser selectedUser) {
        this.selectedUser = selectedUser;
    }
    
    public SiteUser getSelectedUser() {
        return selectedUser;
    }
	
	public String sendMessage() {
		FacesContext.getCurrentInstance().getExternalContext().getFlash().put("mFromSite", "profile");
		FacesContext.getCurrentInstance().getExternalContext().getFlash().put("receiverUser", msgUser);
        return "conversation.jsf?faces-redirect=true";
	}
	
	public void sendMessage(ActionEvent actionEvent) {
		msgUser = actionEvent.getComponent().getAttributes().get("user").toString();
		//FacesContext.getCurrentInstance().getExternalContext().getFlash().put("mFromSite", "profile");
		//FacesContext.getCurrentInstance().getExternalContext().getFlash().put("receiverUser", user);
        //return "conversation.jsf?faces-redirect=true";
	}

    public String navigate(SelectEvent event) {
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("userProfile", event.getObject());  
        return "dateprofile.jsf?faces-redirect=true";
    }
}